{extend name="property/public/insidePageBase" /}
{block name="title"}添加工单信息{/block}
{block name="css"}
{__block__}
<style>
    body{ margin:0; }
    .layui-iconpicker-body.layui-iconpicker-body-page .hide {display: none;}
    body .layui-iconpicker .layui-iconpicker-icon-item{ width: 20.1%; }
    body{  background-color: #ffffff; }
    .layui-upload-img-box { float:left;  margin-bottom: 2px;margin-right: 2px; background: #e0e0e0;  padding: 1px; }
    .layui-upload-img {width: 82px; height: 82px; margin-bottom: 1px;}
</style>
{/block}
{block name="body"}
<div class="layuimini-container">
    <div class="layuimini-main" id="app">
        <div class="layui-form layui-form-pane">
            <div class="layui-form-item">
                <label class="layui-form-label">工单编号</label>
                <div class="layui-input-block">
                    <input type="text" name="repair_no" value="{$repairNo ?? ''}" readonly autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">分类选择</label>
                <div class="layui-input-block">
                    <input type="text" name="cate_id" id="cate-data" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">房间选择</label>
                <div class="layui-input-block">
                    <select name="room_id" lay-filter="room_id" lay-search>
                        <option value="">请选择</option>
                        <option value="0">公共区域</option>
                        {foreach $roomData as $k=>$v}
                        <option value="{$v['id']}">{$v['full_room_name']}</option>
                        {/foreach}
                    </select>
                </div>
            </div>

            <div class="layui-row">
                <div class="layui-col-xs6">
                    <div class="layui-form-item">
                        <label class="layui-form-label indispensable">联系人</label>
                        <div class="layui-input-block">
                            <input type="text" name="contact_name"   placeholder="请输入联系人"  class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <div class="layui-form-item">
                        <label class="layui-form-label indispensable">联系电话</label>
                        <div class="layui-input-block">
                            <input type="text" name="contact_mobile"  placeholder="请输入联系电话" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs6">
                    <div class="layui-form-item">
                        <label class="layui-form-label indispensable">预约日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="hope_date"  placeholder="请选择预约日期"  class="layui-input laydate-type-day">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <div class="layui-form-item">
                        <label class="layui-form-label indispensable">预约时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="hope_time" placeholder="请选择预约时间" class="layui-input laydate-type-time">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">维修参照</label>
                <div class="layui-input-block" id="image_info">
                    <button type="button" class="layui-btn" id="upload_imgs" lay-data="{field: 'picture',data:{dir:'maintain/repair', field:'picture'}}">上传图片</button>
                    <div class="layui-upload-list" id="img_show"> </div>
                    <div style="clear: both"></div>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">工单描述</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入工单描述" class="layui-textarea" name="content"></textarea>
                </div>
            </div>
            <div class="layui-form-item layui-hide">
                <button type="button" class="layui-btn layui-btn-primary replaceUploadImg toggleUpload" lay-data="{}"></button>
                <button class="layui-btn" lay-submit lay-filter="submitBtn" id="submitBtn">提交</button>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
{__block__}
<script>
    layui.use(['form', 'laydate', 'layer', 'layCascader'], function () {
        var form = layui.form,layer = layui.layer,  $ = layui.$, laydate = layui.laydate,layCascader = layui.layCascader;
        laydate.render({
            elem: '.laydate-type-day'
            ,format: 'yyyy-MM-dd'
            ,min: 0
            ,max: 30
        });
        laydate.render({
            elem: '.laydate-type-time',
            type: 'time',
            range: true,
            min: '09:00:00',
            max: '22:00:00',
            format: 'HH:mm',
            btns: ['clear', 'confirm']
        });
        $('#upload_imgs').selectImages({
            confirm:function(res,elem) {
                for(var i in res) {
                    index = (new Date()).getTime()+''+i;
                    $('#img_show').append('<div class="layui-upload-img-box" id="'+index+'">' +
                        '<img src="' + res[i].src + '" class="layui-upload-img checkPictureByImg">' +
                        '<input type="hidden" name="picture[]" value="' + res[i].src + '">' +
                        '<p>' +
                        '<a class="layui-btn layui-btn-xs cftoggleUpload" style="float: left" lay-data="{field: \'picture\',data:{dir:\'picture/repair\', field:\'picture\', replace_upload_index: \''+index+'\'}}">修改</a>' +
                        '<a class="layui-btn layui-btn-xs layui-btn-danger" onclick="this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);" style="float: right">删除</a>' +
                        '</p>' +
                        '</div>'
                    );
                }
            }
        });
        $(document).on('click', '.cftoggleUpload', function () {
            $('.toggleUpload').attr('lay-data', $(this).attr('lay-data'));
            $('.toggleUpload').trigger('click');
        });
        $('.replaceUploadImg').selectImages({
            confirm:function(res,elem,data) {
                let replaceUploadObj = $('#'+data.data.replace_upload_index);
                replaceUploadObj.find('img').attr('src', res[0].src);
                replaceUploadObj.find('img').attr('alt', res[0].src);
                replaceUploadObj.find('input').val(res[0].src);
            }
        });
        layCascader({
            elem: '#cate-data',
            clearable: true,
            value: 0,
            options: {:json_encode($cateNameData,JSON_UNESCAPED_UNICODE)}
        });
    });
</script>
{/block}